package com.grape.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.grape.utils.StringUtils;
import com.grape.vo.BaseVo;
import com.grape.wrapper.BaseWrapper;
import com.grape.domain.SysOperateLog;
import com.grape.mapper.SysOperateLogMapper;
import com.grape.service.ISysOperateLogService;
import lombok.AllArgsConstructor;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * 操作日志表 服务实现类
 *
 * @author  putao
 * @email   2628279194@qq.com
 */
@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class SysOperateLogServiceImpl extends ServiceImpl<SysOperateLogMapper, SysOperateLog> implements ISysOperateLogService {

    private final SysOperateLogMapper sysOperateLogMapper;

    /**
     * 分页
     * @param baseVo    统一分页对象
     * @return          操作日志表集合
     */
    @Override
    public List<SysOperateLog> listData(BaseVo baseVo) {
        QueryWrapper<SysOperateLog> wrapper = new BaseWrapper<SysOperateLog>().init();
        wrapper.like(Strings.isNotBlank(baseVo.getSearch()), "username", baseVo.getSearch());
        wrapper.eq(StringUtils.isNotBlank(baseVo.getColumnName())
                && StringUtils.isNotBlank(baseVo.getSelect()), baseVo.getColumnName(), baseVo.getSelect());
        orderByModifyTimeDesc(wrapper);
        return this.list(wrapper);
    }

    /**
     * 修改
     * @param sysOperateLog 操作日志表对象
     */
    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public void updateData(SysOperateLog sysOperateLog) {
        this.baseUpdate(sysOperateLog);
    }

    /**
     * 新增
     * @param sysOperateLog 操作日志表对象
     * @return              操作日志表对象
     */
    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public SysOperateLog insertData(SysOperateLog sysOperateLog) {
        return this.baseInsert(sysOperateLog);
    }

    /**
     * 删除
     * @param id    单据id
     * @return      删除条数
     */
    @Override
    @Transactional(readOnly = false, rollbackFor = Exception.class)
    public int deleteData(String id) {
        return this.baseDelete(id);
    }

    /**
     * 根据id查询详情
     * @param id    操作日志表id
     * @return      操作日志表对象
     */
    @Override
    public SysOperateLog detail(String id) {
        return this.getById(id);
    }
}
